
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Fcdbas.Core.Windows;

namespace Fcdbas.Core
{
	public sealed class Int
	{
		
		private static SalNumber _ObsoleteWarning_nState = 0;
		private static Regex regexIsDerived = new Regex("[&(): ]", RegexOptions.Compiled);
		[ThreadStatic]
		private static SalWindowHandle contextInQueryEnabledMode = SalWindowHandle.Null;
		[ThreadStatic]
		private static HashSet<string> invokingItems = null;
		
		
		
		public static SalString PalAttrFormatDate(SalDateTime dtValue)
		{
			return dtValue.ToString("yyyy-MM-dd-hhhh.mm.ss");
		}
		
		
		public static SalNumber PalArrayDateCount(SalArray<SalDateTime> Array)
		{
			SalNumber x = 0;
			x = Array.GetUpperBound(1);
			return Vis.NumberChoose(Array.IsEmpty, 0, x + 1);
		}
		public static SalNumber PalArrayHandleCount(SalArray<SalWindowHandle> Array)
		{
			SalNumber x = 0;
			x = Array.GetUpperBound(1);
			return Vis.NumberChoose(Array.IsEmpty, 0, x + 1);
		}
		public static SalNumber PalArrayNumberCount(SalArray<SalNumber> Array)
		{
			SalNumber x = 0;
			x = Array.GetUpperBound(1);
			return Vis.NumberChoose(Array.IsEmpty, 0, x + 1);
		}
		public static SalNumber PalArrayCount(SalArray<SalString> Array)
		{
			SalNumber x = 0;
			x = Array.GetUpperBound(1);
			return Vis.NumberChoose(Array.IsEmpty, 0, x + 1);
		}
		public static SalString PalArrayToString(SalArray<SalString> sArray, SalString sSep)
		{
			SalString salString = "";
			salString = Vis.StrExpand("{%s" + sSep + "}", sArray);
			return salString.Left(salString.Length - 1);
		}
		public static SalString PalBooleanToStr(SalBoolean bTrue)
		{
			return Vis.StrChoose(bTrue, "TRUE", "FALSE");
		}

        public static SalString ClientNameToDbName(SalString sClientName)
        {
            SalNumber x = 0;
            SalString salString = "";
            SalBoolean x2 = false;
            SalNumber x3 = 0;
            x2 = true;
            x3 = 0;
            while (SalString.FirstChar(ref sClientName, ref x) && !(x == 0))
            {
                if (x == 95)
                {
                    x3 += 1;
                }
                else
                {
                    if (x >= 65 && x <= 90 && !x2)
                    {
                        salString = salString + "_" + x.ToCharacter();
                    }
                    else
                    {
                        salString += x.ToCharacter();
                    }
                    x2 = false;
                }
            }
            switch (x3)
            {
                case 1:
                    salString += "_";
                    break;
                case 2:
                    salString += "__";
                    break;
            }
            return salString.ToUpper();
        }
        public static SalString DbNameToClientName(SalString sDbName)
        {
            SalNumber x = 0;
            SalString salString = "";
            SalBoolean x2 = false;
            SalNumber x3 = 0;
            x2 = true;
            x3 = 0;
            while (SalString.FirstChar(ref sDbName, ref x) && !(x == 0))
            {
                if (x == 95)
                {
                    x2 = true;
                    x3 += 1;
                }
                else
                {
                    if (x2)
                    {
                        salString += x.ToCharacter();
                    }
                    else
                    {
                        if (x > 64)
                        {
                            salString += (x + 32).ToCharacter();
                        }
                        else
                        {
                            salString += x.ToCharacter();
                        }
                    }
                    x2 = false;
                    x3 = 0;
                }
            }
            switch (x3)
            {
                case 1:
                    return "_" + salString;
                case 2:
                    return "__" + salString;
                default:
                    return salString;
            }
        }
		
		
		public static SalNumber PalStrHash(SalString sValue)
		{
			long num = 0L;
			int num2 = 0;
			while (num2 < sValue.Length)
			{
				num += (long)(num2 * (int)sValue[num2]);
				num2++;
			}
			return num;
		}
		public static SalString PalStrInsSubStr(SalString lsOrg, SalString sInp, SalNumber nPos)
		{
			return lsOrg.Mid(0, nPos + 1) + sInp + lsOrg.Mid(nPos + 1, lsOrg.Length - nPos - 1);
		}
		
		public static SalBoolean PalStrToBoolean(SalString sTrue)
		{
			return sTrue.ToUpper() == "TRUE";
		}
		
		
		
		
		
	}
}
